#include "particlesystemcompwidget.h"

ParticleSystemCompWidget::ParticleSystemCompWidget(AED_ParticleSystemComp *comp,QWidget *parent) :
    QWidget(parent)
{
    m_comp = comp;

    QVBoxLayout *layout = new QVBoxLayout;
    this->setLayout(layout);

    group = new QGroupBox("Enable");
    layout->addWidget(group);
    layout->setAlignment(group,Qt::AlignTop);
    group->setCheckable(true);

    QVBoxLayout *main_layout = new QVBoxLayout; // La layout principal
    group->setLayout(main_layout);

    QLabel *particle_l = new QLabel("Particle");
    QLabel *totalpart_l = new QLabel("Total Particles");
    QLabel *lifetime_l = new QLabel("System Lifetime");
    QLabel *partlifetime_l = new QLabel("Particle Lifetime");
    QLabel *partvel_l = new QLabel("Particle Velocity");
    QLabel *partsize_l = new QLabel("Initial Particle Size");
    QLabel *random_l = new QLabel("Randomness");
    QLabel *scaling_l = new QLabel("Particle Scaling");
    QLabel *velinter_l = new QLabel("Velocity Interpolation");
    QLabel *interval_l = new QLabel("Interval");

    particle = new QLineEdit();

    fading = new QCheckBox("Fade Out Particles");

    animate = new QCheckBox("Animate Particles");

    rotate = new QCheckBox("Rotate Particles");

    autostart = new QCheckBox("Autostart");

    autokill = new QCheckBox("Kill at end");

    loop = new QCheckBox("Loop");


    totalparticles = new QSpinBox;
    totalparticles->setMinimum(0);
    totalparticles->setMaximum(10000);

    lifetime = new QSpinBox;
    lifetime->setMinimum(0);
    lifetime->setMaximum(10000);

    particle_lifetime = new QSpinBox;
    particle_lifetime->setMinimum(0);
    particle_lifetime->setMaximum(10000);

    randomness = new QSpinBox;
    randomness->setMinimum(0);

    interval = new QSpinBox;
    interval->setMinimum(0);
    interval->setMaximum(10000);

    particlevel = new QDoubleSpinBox;
    particlevel->setMinimum(0);
    particlevel->setDecimals(5);

    particlesize = new QDoubleSpinBox;
    particlesize->setMinimum(0);

    scaling = new QDoubleSpinBox;
    scaling->setDecimals(5);
    scaling->setRange(-10,10);




    velint = new QDoubleSpinBox;
    velint->setMinimum(0);


    QHBoxLayout* hbox1 = new QHBoxLayout;
    QHBoxLayout* hbox2 = new QHBoxLayout;
    QHBoxLayout* hbox3 = new QHBoxLayout;
    QHBoxLayout* hbox4 = new QHBoxLayout;
    QHBoxLayout* hbox5 = new QHBoxLayout;
    QHBoxLayout* hbox6 = new QHBoxLayout;
    QHBoxLayout* hbox7 = new QHBoxLayout;
    QHBoxLayout* hbox8 = new QHBoxLayout;

    hbox1->addWidget(particle_l);
    hbox1->addWidget(particle);
    hbox7->addWidget(totalpart_l);
    hbox7->addWidget(totalparticles);
    hbox2->addWidget(lifetime_l);
    hbox2->addWidget(lifetime);
    hbox2->addWidget(partlifetime_l);
    hbox2->addWidget(particle_lifetime);
    hbox7->addWidget(interval_l);
    hbox7->addWidget(interval);
    hbox3->addWidget(partsize_l);
    hbox3->addWidget(particlesize);
    hbox3->addWidget(partvel_l);
    hbox3->addWidget(particlevel);
    hbox8->addWidget(scaling_l);
    hbox8->addWidget(scaling);
    hbox4->addWidget(fading);
    hbox4->addWidget(animate);
    hbox4->addWidget(rotate);
    hbox5->addWidget(random_l);
    hbox5->addWidget(randomness);
    hbox5->addWidget(velinter_l);
    hbox5->addWidget(velint);
    hbox6->addWidget(autostart);
    hbox6->addWidget(autokill);
    hbox6->addWidget(loop);

    main_layout->addLayout(hbox1);
    main_layout->addLayout(hbox7);
    main_layout->addLayout(hbox2);
    main_layout->addLayout(hbox3);
    main_layout->addLayout(hbox8);
    main_layout->addLayout(hbox4);
    main_layout->addLayout(hbox5);
    main_layout->addLayout(hbox6);

    connect(group, SIGNAL(toggled(bool)),
                this,SLOT(SetEnabled(bool)));
    connect(particle, SIGNAL(textChanged(QString)),
            this,SLOT(SetParticle(QString)));
    connect(totalparticles,SIGNAL(valueChanged(int)),
            this,SLOT(SetTotalParticles(int)));
    connect(lifetime,SIGNAL(valueChanged(int)),
            this,SLOT(SetLifeTime(int)));
    connect(particlevel,SIGNAL(valueChanged(double)),
            this,SLOT(SetParticleVelocity(double)));
    connect(particlesize,SIGNAL(valueChanged(double)),
            this,SLOT(SetParticleSize(double)));
    connect(randomness,SIGNAL(valueChanged(int)),
            this,SLOT(SetRandomness(int)));
    connect(fading,SIGNAL(toggled(bool)),
            this,SLOT(SetFading(bool)));
    connect(animate,SIGNAL(toggled(bool)),
            this,SLOT(SetAnimate(bool)));
    connect(autostart,SIGNAL(toggled(bool)),
            this,SLOT(SetAutoStart(bool)));
    connect(autokill,SIGNAL(toggled(bool)),
            this,SLOT(SetAutoKill(bool)));
    connect(loop,SIGNAL(toggled(bool)),
            this,SLOT(SetLoop(bool)));
    connect(rotate,SIGNAL(toggled(bool)),
            this,SLOT(SetParticleRotation(bool)));
    connect(scaling,SIGNAL(valueChanged(double)),
            this,SLOT(SetScaling(double)));
    connect(velint,SIGNAL(valueChanged(double)),
            this,SLOT(SetVelocityInterpolation(double)));
    connect(interval,SIGNAL(valueChanged(int)),
            this,SLOT(SetInterval(int)));
    connect(particle_lifetime,SIGNAL(valueChanged(int)),
            this,SLOT(SetParticleLifetime(int)));


}

void ParticleSystemCompWidget::setComp(AED_ParticleSystemComp *comp){
    m_comp = comp;
    if(!m_comp){
        group->setEnabled(false);
    }else{
        group->setEnabled(true);
        group->setChecked(comp->IsEnabled());

        particle->setText(m_comp->GetParticle());
        fading->setChecked(m_comp->GetFading());
        animate->setChecked(m_comp->GetAnimate());
        rotate->setChecked(m_comp->GetParticleRotation());
        autostart->setChecked(m_comp->GetAutoStart());
        autokill->setChecked(m_comp->GetAutoKill());
        loop->setChecked(m_comp->GetLoop());
        totalparticles->setValue(m_comp->GetTotalParticles());
        lifetime->setValue(m_comp->GetLifeTime());
        particle_lifetime->setValue(m_comp->GetParticleLifeTime());
        randomness->setValue(m_comp->GetRandomness());
        interval->setValue(m_comp->GetInterval());
        particlevel->setValue(m_comp->GetParticleVelocity());
        particlesize->setValue(m_comp->GetParticleSize());
        scaling->setValue(m_comp->GetScaling());
        velint->setValue(m_comp->GetVelocityInterpolation());
    }
}
